

package com.hex.ds.em.hcdp.pack.entity;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import java.util.Locale;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.validation.annotation.Validated;

/**
 * 脚本打包扫描清单
 *
 * @author Wang zhihao
 * @date 2023-09-13 18:05:43
 */
@Data
@Validated
@Accessors(chain = true)
public class ScriptPackScanListEntity{
private static final long serialVersionUID = 1L;

    /**
     * 扫描结果ID
     */
    private String id;

    /**
     * 脚本打包任务ID
     */
    private String scriptPackTaskId;

    /**
     * 扫描文件名
     */
    private String scanFileName;

    /**
     * 文件路径
     */
    private String scanFilePath;

    /**
     * 文件归属(清单、初始化脚本、业务脚本、周期脚本)
     */
    private String fileAffiliation;

    /**
     * 文件归属名称(清单、初始化脚本、业务脚本、周期脚本)
     */
    private String fileAffiliationName;

    /**
     * 带路径的文件名
     */
    private String fileNameWithPath;

    /**
     * 扫描开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone = "GMT+8")
    private Date createTime;

    /**
     * 扫描结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone = "GMT+8")
    private Date lastUpdateTime;

    /**
     * 扫描结果(成功, 失败, 扫描中)
     */
    private String scanState;

    /**
     * 删除标识
     */
    private String del;

    /**
     * 日志文件路径
     */
    private String runLogPath;

    public String getScanFilePath() {
        return StrUtil.isBlank(scanFilePath) ? scanFilePath : scanFilePath.replace("\\", "/");
    }

    public String getFileAffiliationName() {
        switch (StrUtil.isNotBlank(fileAffiliation) ? fileAffiliation.toUpperCase(Locale.ROOT) : "") {
            case "INIT":
                return "初始化脚本";
            case "PERIOD":
                return "周期脚本";
            case "SERVICE":
                return "推送下载稽核脚本";
            default:
                return "";
        }
    }

    public String getFileNameWithPath() {
        switch (StrUtil.isNotBlank(fileAffiliation) ? fileAffiliation.toUpperCase(Locale.ROOT) : "") {
            case "INIT":
            case "PERIOD":
                return scanFileName;
            case "SERVICE":
                return StrUtil.isBlank(scanFilePath) ? scanFileName
                        : scanFilePath.replace("\\", "/").split("/")[scanFilePath.replace("\\", "/").split("/").length-2] + "/" + scanFileName;
            default:
                return scanFileName;
        }
    }
}
